//index.js
//获取应用实例
const app = getApp()
// import Dialog from '../../../miniprogram_npm/_vant-weapp@0.5.18@vant-weapp/dialog/dialog';
Page({
  data: {
    params: {},
    detailData: {},
    typeIndex: 1,
    swiperIndex: 0,
    showPopup: false,
  },
  onLoad: function (e) {
    this.setData({
      params: e
    })
    this.getDetailData(e)
  },
  /**
   * 获取房源详情
   */
  getDetailData(e) {
    app.globalData.request('get', 'applet/house/HouseDetail', e).then(res => {
      this.setData({
        detailData: res.data
      })
    }).catch(err => {

    })
  },
  /**
   * 切换图片显示 swiper
   */
  changeSwiper(e) {
    this.setData({
      typeIndex: e.currentTarget.dataset.type,
      swiperIndex: 0
    })
  },
  previewSwiper(e) {
    wx.previewImage({
      current: e.currentTarget.dataset.current, // 当前显示图片的http链接
      urls: this.data.typeIndex == 1 ? this.data.detailData.indoor_drawings : this.data.detailData.floor_plans // 需要预览的图片http链接列表
    })
  },
  /**
   * 预约看房
   */
  booking() {
    if(!wx.getStorageSync('id')) {
      wx.showModal({
        title: '未登录',
        content: '您还未登录, 请登录',
        success(e) {
          if(e.confirm) {
            wx.navigateTo({
              url: '/pages/mine/login/login',
            })
          }
        },
      })
    } else {
      let form = {
        house_id: this.data.params.id,
        keeper_id: wx.getStorageSync('id'),
        create_id: this.data.detailData.create_id,
        token: wx.getStorageSync('token'),
        type: this.data.params.type,
        order_time: ''
      }
      app.globalData.request('post', 'applet/house/AddOrderHouse', form).then(res => {
        this.setData({
          showPopup: true
        })
      }).catch(err => {
      })
    }
  },
  /**
   * 点击关闭弹窗
   */
  closeDialog() {
    this.setData({
      showPopup: false
    })
    wx.navigateBack()
  }
})
